package com.htfyun.serialport.uartservo.AX12_Servo;

import com.htfyun.serialport.uartservo.IServoReadDataAnalyze;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class AX12_ServoReadDataAnalyze extends IServoReadDataAnalyze<AX12_ReceivedSerialPacket> {

    //我们的AX12的一个包一般是最多是12bytes, 这里定义成20个bytes, 如果length大于此值, 那么数据就出错了 我们需要抛弃他.
    private final int PACKET_MAX_LENGTH = 20;

    @Override
    protected AX12_ReceivedSerialPacket createReceivedSerialPacket(ByteBuffer byteBuffer) {
        return new AX12_ReceivedSerialPacket(byteBuffer);
    }

    @Override
    protected ByteBuffer getHeader() {
        return AX12_ReceivedSerialPacket.getHeaderByteBuffer();
    }

    @Override
    protected int positionOfPacketLengthOffsetFromHeader() {
        return AX12_ReceivedSerialPacket.LENGTH_OFFSET_FROM_HEADER;
    }

    @Override
    protected int numBytesOfPacketLength() {
        return 1;
    }

    @Override
    protected int getMinSizeOfValidPacket() {
        return AX12_ReceivedSerialPacket.PACKAGE_MIN_SIZE;
    }

    @Override
    protected int getMaxLengthOfPacket() {
        return PACKET_MAX_LENGTH;
    }

    @Override
    protected int getExtraLength() {
        return AX12_ReceivedSerialPacket.SIZE_OF_FIX_PREFIX_DATA;
    }

    @Override
    protected ByteOrder getByteOrder() {
        return ByteOrder.LITTLE_ENDIAN;
    }
}
